package com.course.business.controller.admin;


import com.course.server.domain.File;
import com.course.server.dto.FileDto;
import com.course.server.dto.PageDto;
import com.course.server.dto.ResponseDto;
import com.course.server.service.FileService;
import com.course.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/*
* 如果返回的是json格式的数据,用@RestController
* 如果返回的是页面,使用@Controlle
* */

@RestController
@RequestMapping("/admin/file")
public class FileController {

    //---------------固定开始---------------
    //定义日志获取
    private static final Logger LOG = LoggerFactory.getLogger(FileController.class);
    public static final String BUSINESS_NAME = "文件";

    //---------------固定注入---------------
    @Resource
    private FileService fileService;


    /*
     * 列表查询
     * */
    @RequestMapping("/list")
    public ResponseDto list(@RequestBody PageDto pageDto){
        LOG.info("pageDto:{}",pageDto);
        ResponseDto responseDto = new ResponseDto();
        fileService.list(pageDto);//返回业务执行查询列表结果
        responseDto.setContent(pageDto);
        return responseDto ;
    }

    /*
     * 状态修改查询
     * */
    @RequestMapping("/changedStatus")
    public ResponseDto changedStatus(@RequestBody FileDto fileDto){
        LOG.info("fileDto:{}",fileDto);
        ResponseDto responseDto = new ResponseDto();
        fileService.changedStatus(fileDto);
        responseDto.setContent(fileDto);
        return responseDto ;
    }

    /*
    * 保存活动
    * */
    @RequestMapping("/save")
    public ResponseDto save(@RequestBody FileDto fileDto){
        //保存校验
       

        LOG.info("fileDto:{}",fileDto);
        ResponseDto responseDto = new ResponseDto();
        fileService.save(fileDto);
        responseDto.setContent(fileDto);
        return responseDto ;
    }

    /*
     * 根据id查询活动
     * */
    @RequestMapping(value="/selectId/{id}",method = RequestMethod.GET)
    public ResponseDto selectById(@PathVariable String id){
        ResponseDto responseDto = new ResponseDto();
        FileDto fileDto= fileService.selectById(id);
        responseDto.setContent(fileDto);
        return responseDto;
    }

    /*
     * 根据name查询活动
     * 生成器启动的时候这部分需要手动更改因为实体名称不一致
     * */
    @RequestMapping("/selectName")
    public ResponseDto selectByName(@RequestBody PageDto pageDto){
        ResponseDto responseDto = new ResponseDto();
        fileService.selectByName(pageDto);//返回业务执行查询列表结果
        responseDto.setContent(pageDto);
        return responseDto ;
    }

    /*
    * 删除活动
    * */
    @DeleteMapping("/delete/{id}")
    //@PathVariable路径变量映射
    public ResponseDto delete(@PathVariable String id){
        ResponseDto responseDto = new ResponseDto();
        fileService.delete(id);
        return responseDto;
    }
}
